package com.h2cloud.aop;

/**
 * @Package: com.h2cloud.aop
 * @ClassName: Main
 * @Author: wulongkai
 * @CreateTime: 2023/9/26 17:54
 * @Description:
 */

import com.sun.tools.javac.util.List;

import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        // 创建实际的服务对象
        UserService userService = new UserServiceImpl();

        // 创建代理处理器
        UserProxyHandler proxyHandler = new UserProxyHandler(userService);

        // 创建代理对象
        UserService proxy = (UserService) Proxy.newProxyInstance(
                UserService.class.getClassLoader(),
                new Class[]{UserService.class, UserService2.class},
                proxyHandler
        );

        // 调用代理对象的方法
        proxy.saveUser("Alice");
        String user = proxy.getUser("Bob");
        System.out.println("user = " + user);

        for (Method declaredMethod : proxy.getClass().getDeclaredMethods()) {
            System.out.println("declaredMethod.getName() = " + declaredMethod.getName());
        }

        int i = Integer.parseInt("-10");
        System.out.println("i = " + i);

        List<Integer> numbers = List.of(1, 2, 3, 4, 5);

        // 使用Java Stream API将List<Integer>中的值拼接为"xx行、xx行"的字符串
        String result = numbers.stream()
                .map(number -> number + "行")
                .collect(Collectors.joining("、"));

        System.out.println(result);

        String message = "234";
        String substring = message.substring(0, 300);
        System.out.println("substring = " + substring);
    }
}

